package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.BrandService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.entity.Brand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "品牌接口", tags = "品牌接口")
@RequestMapping("/api/brand")
@RestController
public class BrandController {

    @Autowired
    BrandService brandService;

    @ApiOperation("获取品牌分页")
    @PreAuthorize("hasAuthority('product.brand')")
    @PostMapping("/getBrandPage")
    public ResultData<BasePageResp<Brand>> getBrandPage(@RequestBody PageReq req) {
        return brandService.getBrandPage(req);
    }

    @ApiOperation("获取所有品牌列表")
    @GetMapping("/getBrandList")
    public ResultData<List<Brand>> getBrandList() {
        return brandService.getBrandList();
    }

    @OperatorLog("添加或编辑品牌")
    @ApiOperation("添加或编辑品牌")
    @PreAuthorize("hasAuthority('product.brand.edit.auth')")
    @PostMapping("/editBrand")
    public BaseResp editBrand(@RequestBody Brand brand) {
        return brandService.editBrand(brand);
    }

    @ApiOperation("获取品牌详情")
    @GetMapping("/getBrandDetail")
    public ResultData<Brand> getBrandDetail(@RequestParam("id") Long id) {
        return brandService.getBrandDetail(id);
    }

    @OperatorLog("删除品牌")
    @ApiOperation("删除品牌")
    @PreAuthorize("hasAuthority('product.brand.edit.auth')")
    @GetMapping("/deleteBrand")
    public BaseResp deleteBrand(@RequestParam("id") Long id) {
        return brandService.deleteBrand(id);
    }
}
